package com.wtwd.campus.receiver;

import com.wtwd.campus.entity.MqGeneralSwitchResult;
import com.wtwd.campus.entity.MqLocationData;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.InjectFeignService;
import com.wtwd.campus.utils.LocationUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class SetNoDistrubSwitchReceiver implements Receiver {
    @Autowired
    private IRMFeignClientService irmFeignClientService;

    @Override
    public String parseMessage(String data) {
        // *WT,866248050395985,V4,CLASSSWITCH,174444,1,174725,A,2250.2153,N,11391.6210,E,1.49,0,020621,FFFFDFFF
        //分割字符串获取指令信息
        String[] split = data.split(",");
        String imei = split[1];
        String messageType = split[2];
        String type = split[3];
        String commandNumber = split[4];
        String switchFlag=split[5];//免打扰设置的开关，1-开 0-关
        String time = split[6];//指令回复的时间（时分秒）
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];//年月日
        String deviceStatus = split[15];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        MqGeneralSwitchResult mqGeneralSwitchResult = new MqGeneralSwitchResult();
        mqGeneralSwitchResult.setCommandNumber(commandNumber);
        mqGeneralSwitchResult.setDeviceDate(date);
        mqGeneralSwitchResult.setImei(imei);
        mqGeneralSwitchResult.setDeviceDate(deviceStatus);
        mqGeneralSwitchResult.setResult(Integer.parseInt(switchFlag));
        mqGeneralSwitchResult.setDeviceTime(time);
        MqLocationData mqLocationData = new MqLocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        mqGeneralSwitchResult.setMqLocationData(mqLocationData);
        InjectFeignService.getIrmFeignClientService().classModeSwitchResponse(mqGeneralSwitchResult);
        return imei;
    }
}
